namespace muduoDotNet
{
    /// <summary>
    /// TimerId类，用于标识定时器
    /// </summary>
    public struct TimerId : IEquatable<TimerId>
    {
        private readonly Timer _timer;
        private readonly long _sequence;

        internal TimerId(Timer timer, long seq)
        {
            _timer = timer;
            _sequence = seq;
        }

        public Timer Timer => _timer;
        public long Sequence => _sequence;

        public bool Equals(TimerId other)
        {
            return _timer == other._timer && _sequence == other._sequence;
        }

        public override bool Equals(object obj)
        {
            if (obj is TimerId)
            {
                return Equals((TimerId)obj);
            }
            return false;
        }

        public override int GetHashCode()
        {
            return _timer.GetHashCode() ^ _sequence.GetHashCode();
        }

        public static bool operator ==(TimerId left, TimerId right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(TimerId left, TimerId right)
        {
            return !left.Equals(right);
        }
    }
}